package com.frxuexi.park2305.my

import android.view.View
import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.entity.MyApproveBean
import com.frxuexi.lib_base.entity.NewsBeanItem
import com.frxuexi.lib_base.entity.ParkBeanItem
import com.frxuexi.lib_base.entity.VisitBeanItem
import com.frxuexi.park.R
import com.frxuexi.park.databinding.ItemParkBinding
import com.frxuexi.park2305.databinding.ItemNewsBinding
import com.frxuexi.visit.databinding.ItemVisitBinding

class MyApproveAdapter:BaseMultiItemQuickAdapter<MyApproveBean,BaseViewHolder>() {

    init {
        addItemType(0,R.layout.item_park)
        addItemType(1, com.frxuexi.visit.R.layout.item_visit)
        addItemType(2, com.frxuexi.park2305.R.layout.item_news)
    }

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemParkBinding>(viewHolder.itemView)
    }

    override fun convert(helper: BaseViewHolder, item: MyApproveBean) {
        if(item.itemType==0){
            val binding = DataBindingUtil.getBinding<ItemParkBinding>(helper.itemView)!!
            binding.bean=item as ParkBeanItem

            binding?.parkStatus?.apply {
                binding.parkGroup.visibility=View.GONE
                when (item.spaceStatus) {
                    "空闲" -> {
                        setTextColor(context.getColor(com.frxuexi.lib_base.R.color.green))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_status)
                        binding.parkGroup.visibility=View.VISIBLE
                    }

                    "已占用" -> {
                        setTextColor(context.getColor(com.frxuexi.lib_base.R.color.blue))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_zhanyong)
                    }

                    else -> {
                        setTextColor(context.getColor(com.frxuexi.lib_base.R.color.darkorange))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_weihu)
                    }
                }
            }
        }else if(item.itemType==1){
            val binding = DataBindingUtil.getBinding<ItemVisitBinding>(helper.itemView)!!
            binding.bean=item as VisitBeanItem
            binding.visitGroup.visibility=View.GONE
            binding.visitStatus.apply {
                when(item.visitStatus){
                    "待审核"->{
                        setTextColor(context.getColor(com.frxuexi.lib_base.R.color.blue))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_zhanyong)
                        binding.visitGroup.visibility=View.VISIBLE
                    }
                    "已通过"->{
                        setTextColor(context.getColor(com.frxuexi.lib_base.R.color.green))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_status)
                    }
                    "驳回"->{
                        setTextColor(context.getColor(com.frxuexi.lib_base.R.color.redfont))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_red)
                    }
                }
            }

            if(item.requestParking){
                binding.visitCar.setImageResource(com.frxuexi.lib_base.R.drawable.ic_action_car)
                binding.visitCarNo.setText("已申请车位")
                binding.visitCarNo.setTextColor(context.getColor(com.frxuexi.lib_base.R.color.blue))
            }else{
                binding.visitCar.setImageResource(com.frxuexi.lib_base.R.drawable.ic_action_nocar)
                binding.visitCarNo.setText("未申请车位")
                binding.visitCarNo.setTextColor(context.getColor(com.frxuexi.lib_base.R.color.lightgray))
            }
        }else{
            val binding = DataBindingUtil.getBinding<ItemNewsBinding>(helper.itemView)!!
            binding.bean=item as NewsBeanItem
        }
    }
}